﻿<template>
    <el-dialog :title="titleMap[mode]" v-model="visible" :width="1300" destroy-on-close>
        <el-form
            :model="entityObj"
            :rules="rules"
            :disabled="mode == 'Show'"
            ref="dialogForm"
            label-width="100px"
        >
            <el-row style="margin-top: 24px;">
                <el-col :span="6">
                    <el-form-item
                        label-width="120px"
                        label="审核时间:"
                        v-show="mode=='detail'"
                    >{{entityObj.auditDate?.slice(0, 10)}}</el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item
                        label-width="120px"
                        label="审核人:"
                        v-show="mode=='detail'"
                    >{{entityObj.auditName}}</el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label-width="120px" label="审核状态:">{{entityObj.auditStatusDesc}}</el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item
                        label-width="120px"
                        label="审核备注:"
                        v-show="mode=='detail'"
                    >{{entityObj.auditRemarks}}</el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="6">
                    <el-form-item label-width="120px" label="供应商:">{{entityObj.supplierName}}</el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label-width="120px" label="入库时间:">{{entityObj.inStockDate?.slice(0, 10)}}</el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label-width="120px" label="入库编号:">{{entityObj.inStockCode}}</el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label-width="120px" label="入库类型:">{{entityObj.inStockTypeDesc}}</el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="6">
                    <el-form-item label-width="120px" label="入库仓库:">{{entityObj.warehouseName}}</el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label-width="120px" label="创建人:">{{entityObj.crName}}</el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label-width="120px" label="创建时间:">{{entityObj.crDate?.slice(0, 10)}}</el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label-width="120px" label="修改人:">{{entityObj.edName}}</el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="6">
                    <el-form-item label-width="120px" label="最后修改时间:">{{entityObj.edDate?.slice(0, 10)}}</el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label-width="120px" label="创建类型:">{{entityObj.createTypeDesc}}</el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label-width="120px" label="来源:">{{entityObj.sourceTypeDesc}}</el-form-item>
                </el-col>
                <!-- <el-col :span="6">
                    <el-form-item
                        label-width="120px"
                        label="关联订单:"
                    >{{entityObj.purchaseOrderCode}}</el-form-item>
                </el-col> -->
                <el-col :span="6">
                    <el-form-item label-width="120px" label="关联订单:">{{entityObj.orderCode}}</el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="8">
                    <el-form-item label-width="120px" label="备注:">{{entityObj.remarks}}</el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label-width="120px" label="入库物料:">
                        <el-table
                            :data="entityObj.inStockItems"
                            :border="true"
                            style="width: 100%"
                            :row-class-name="tableRowClassName"
                        >
                            
                            <el-table-column label="关联单号" prop="orderCode" width="170" v-if="orgType==1">
                                <!-- <template #default="scope">
                                    <div v-if="scope.row.purchaseOrderCode">{{scope.row.purchaseOrderCode}}</div>
                                    <div v-else-if="scope.row.deliveryOrderCode">{{scope.row.deliveryOrderCode}}</div>
                                </template> -->
                            </el-table-column>
                            <el-table-column label="物料编码" prop="materialCode" />
                            <el-table-column label="物料名称" prop="materialName" width="150"/>
                            <el-table-column label="分类" prop="materialTypeName" />
                            <el-table-column label="规格" prop="materialSpecs" />
                            <el-table-column label="单位" prop="unitName" />
                            <el-table-column label="数量" prop="qty" />
                            <el-table-column label="单价" prop="price" />
                            <el-table-column label="金额" prop="totalAmount" />
                            <el-table-column label="备注" prop="remarks" />
                        </el-table>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label-width="120px" label="审核备注">
                        <el-input v-model="entityObj.auditRemarks" type="textarea" :rows="2" />
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <template #footer>
            <div v-show="mode=='audit'">
                <el-button @click="handleBeforeClose">取 消</el-button>
                <el-button
                    v-if="mode != 'show'"
                    type="primary"
                    :loading="isSaveing"
                    @click="submit(3)"
                >审核通过</el-button>
                <el-button
                    v-if="mode != 'show'"
                    type="primary"
                    :loading="isSaveing"
                    @click="submit(0)"
                >审核不通过</el-button>
            </div>
        </template>
    </el-dialog>
</template>



<script>
import tool from "@/utils/tool";
export default {
    emits: ["success", "closed"],
    data() {
        return {
            tableRowClassName: "warning-row",
            tableRowClassName1: "success-row",
            mode: "detail",
            titleMap: {
                detail: "详情",
                audit: "审核",
            },
            entityObj: {},
            materialState: false,
            queryList: {},
            visible: false,
            isSaveing: false,
            needSaveFlag: false,
            orgType:0
        };
    },
    computed: {},
    methods: {
        //显示=
        open(mode = "detail") {
            this.mode = mode;
            this.visible = true;
            return this;
        },
        //表单提交方法
        submit(status) {
            this.$refs.dialogForm.validate(async (valid) => {
                if (valid) {
                    this.isSaveing = true;
                    try {
                        var returnValue =
                            await this.$API.auth.PostProcessApi.post(
                                "in-stock/audit",
                                { ...this.entityObj, auditStatus: status }
                            );
                        if (returnValue.status == 200) {
                            this.$message.success("操作成功");
                            this.$emit("fatherMethod");
                            this.isSaveing = false;
                            this.visible = false;
                        } else {
                            this.$message.error("操作失败:" + returnValue.msg);
                            this.isSaveing = false;
                        }
                    } catch (error) {
                        this.loading = false;
                        this.isSaveing = false;
                        return false;
                    }
                }
            });
        },
        //表单注入数据
        async setData(id) {
            if (id && id > 0) {
                try {
                    var returnValue = await this.$API.auth.GetProcessApi.get(
                        "in-stock/detail/" + id,
                        {}
                    );
                    console.log("666")
                    if (returnValue.status == 200) {
                        this.entityObj = returnValue.response;
                        this.entityObj.suppliers = {
                            supplierId: this.entityObj.supplierId,
                            supplierName: this.entityObj.supplierName,
                        };
                        this.entityObj.warehouses = {
                            warehouseId: this.entityObj.warehouseId,
                            warehouseName: this.entityObj.warehouseName,
                        };
                    } else {
                        this.$message.error("操作失败:" + returnValue.msg);
                    }
                } catch (error) {
                    this.loading = false;
                    return false;
                }
            }
        },
        async initOptions() {},
    },
    async mounted() {
        await this.initOptions();
        this.orgType = tool.data.get("USER_INFO").AccountType;
        var inStockId=this.$route.query.inStockId; 
        if(inStockId){
            this.setData(inStockId);
        }
    },
};
</script>

<style scoped>
.el-table .warning-row {
    --el-table-tr-bg-color: var(--el-color-warning-light-9);
}
.el-table .success-row {
    --el-table-tr-bg-color: var(--el-color-success-light-9);
}
.el-form-item {
    margin-bottom: 8px !important;
}
</style>
